package com.dragon.app.controller.attendance;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dragon.app.config.annotation.Login;
import com.dragon.common.model.Insert;
import com.dragon.common.model.ResponseData;
import com.dragon.logical.service.avttendance.ISiteService;
import com.dragon.repository.domain.dto.SiteDTO;
import com.dragon.repository.domain.vo.SiteVO;
import com.dragon.repository.entity.Site;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 位置表 前端控制器
 * </p>
 *
 * @author sy
 * @since 2023-08-28
 */
@RestController
@RequestMapping("site")
@Api(tags = "轨迹行动位置")
public class SiteController {

    @Autowired
    private ISiteService service;

    @GetMapping("list")
    @ApiOperation("获取行动位置列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "adminId", value = "用户id", required = false, type = "int"),
            @ApiImplicitParam(name = "search", value = "搜索参数（名字）", required = false, type = "int"),
            @ApiImplicitParam(name = "page", value = "页码", required = true, type = "int"),
            @ApiImplicitParam(name = "limit", value = "条数", required = true, type = "int")
    })
    public ResponseData<List<SiteDTO>> list(@RequestParam(required = false) Integer adminId,
                                            @RequestParam(required = false) String search,
                                            @RequestParam Integer page,
                                            @RequestParam Integer limit){
        Page<Site> list = service.getList(adminId, search, page, limit);
        return ResponseData.success(SiteDTO.convertList(list.getRecords()),list.getTotal());
    }

    @PostMapping("add")
    @ApiOperation(value = "添加")
    public ResponseData siteAdd(@RequestBody @Validated(Insert.class)SiteVO vo){
        service.add(SiteVO.convert(vo));
        return ResponseData.success();
    }

    @PostMapping("judgement")
    @ApiOperation(value = "判断人员")
    public ResponseData siteAdd(@ApiParam(hidden = true) @Login Integer adminId){
        return ResponseData.success(service.judgementPerson(adminId));
    }
}
